/**
 * Base response formatter utilities
 */
class ResponseFormatter {
  /**
   * Success response
   */
  static success(res, data, message = 'Success', statusCode = 200) {
    return res.status(statusCode).json({
      success: true,
      message,
      data,
    });
  }

  /**
   * Success response with pagination
   */
  static successWithPagination(res, data, pagination, message = 'Success', statusCode = 200) {
    return res.status(statusCode).json({
      success: true,
      message,
      data,
      pagination,
    });
  }

  /**
   * Error response
   */
  static error(res, message = 'Error', statusCode = 500, details = null) {
    const response = {
      success: false,
      error: {
        status: statusCode,
        message,
      },
    };

    if (details) {
      response.error.details = details;
    }

    return res.status(statusCode).json(response);
  }

  /**
   * Validation error response
   */
  static validationError(res, errors) {
    return res.status(400).json({
      success: false,
      error: {
        status: 400,
        message: 'Validation Error',
        details: errors,
      },
    });
  }

  /**
   * Not found response
   */
  static notFound(res, message = 'Resource not found') {
    return res.status(404).json({
      success: false,
      error: {
        status: 404,
        message,
      },
    });
  }

  /**
   * Unauthorized response
   */
  static unauthorized(res, message = 'Unauthorized') {
    return res.status(401).json({
      success: false,
      error: {
        status: 401,
        message,
      },
    });
  }

  /**
   * Forbidden response
   */
  static forbidden(res, message = 'Forbidden') {
    return res.status(403).json({
      success: false,
      error: {
        status: 403,
        message,
      },
    });
  }
}

module.exports = ResponseFormatter;